<?php
namespace app\decorate\controller;
use app\AdminRest;
use think\App;
use think\Request;
use app\decorate\model\AdminHousewear as housewear_model;

class AdminHousewear extends AdminRest{
    protected $model;
    public function __construct(App $app) {
        parent::__construct($app);
        $this->model = new housewear_model();
    }

    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:户型居室列表
     */
    public function housewearList(){
        $input = $this->_input;
        if(!empty($input['title'])){
            $dis[] = ['title','like',"%\\".$input['title']."%"];
        }
        $dis[] = ['uniacid','=',$this->_uniacid];
        $data  = $this->model->housewearList($dis,$input['limit']);
        return $this->success($data);
    }

    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:添加户型居室
     */
    public function housewearAdd(){
        $input = $this->_input;
        $input['uniacid'] = $this->_uniacid;
        $info = $this->model->housewearInfo(['title'=>$input['title'],'uniacid'=>$this->_uniacid]);
        if($info){
            return $this->error('户型设置已存在');
        }
        $res   = $this->model->housewearAdd($input);
        return $this->success($res);
    }

    /**
     * User: chenniang
     * Date: 2019-10-09 15:59
     * @return \think\Response
     * descption:编辑|回显户型居室
     */
    public function housewearUpdate(){
        $input = $this->_input;
        if(count($input)>1){
            if(isset($input['title'])){
                $info = $this->model->housewearInfo(['title'=>$input['title'],'uniacid'=>$this->_uniacid]);
                if($info&&$info['id'] != $input['id']){
                    return $this->error('户型设置已存在');
                }
            }
            $data = $this->model->housewearUpdate(['id'=>$input['id']],$input);
        }else{
            $data = $this->model->housewearInfo(['id'=>$input['id']]);
        }
        return $this->success($data);
    }








}
